package com.ldj.struts.action;

import java.util.Hashtable;
import java.util.List;
import java.util.Vector;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.actions.DispatchAction;

import com.ldj.common.SystemSession;
import com.ldj.hibernate.ViewContract;
import com.ldj.hibernate.ViewContractDAO;
import com.ldj.hibernate.ViewContractId;

public class ViewContractAction extends DispatchAction {

	public ActionForward find(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) {
		return mapping.findForward("find");
	}
	
	public ActionForward xls(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) {
		ViewContractDAO dao = new ViewContractDAO(request, response);
		String areaCode = request.getParameter("areaCode");
		List list = dao.findFromAreaCode(areaCode);
		request.setAttribute("list", list);
		request.setAttribute("organ", SystemSession.getUserOrgan(request));
		return mapping.findForward("xls");
	}
	
	public ActionForward detail(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) {
		ViewContractDAO dao = new ViewContractDAO(request, response);
		String areaCode = request.getParameter("areaCode");
		List list = dao.findFromAreaCode(areaCode);
		request.setAttribute("list", list);
		return mapping.findForward("detail");
	}
	
	public ActionForward pic(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) {
		ViewContractDAO dao = new ViewContractDAO(request, response);
		String areaCode = request.getParameter("areaCode");
		List list = dao.findFromAreaCode(areaCode);
		Hashtable rd = new Hashtable();
		rd.put("barTitle", "各类型企业合同签订情况柱状图");
		rd.put("domain", "企业类型");
		rd.put("range", "人数");
		List dList = new Vector();
		if(list != null && list.size() > 0){
			for(int i = 0; i < list.size(); i ++){
				ViewContract vc = (ViewContract)list.get(i);
				ViewContractId contract = vc.getId();
				Hashtable hd = new Hashtable();
				hd.put("name", contract.getTypeName());
				hd.put("title", "职工总数");
				hd.put("value", contract.getWorkerTotalNum());
				dList.add(hd);
				hd = new Hashtable();
				hd.put("name", contract.getTypeName());
				hd.put("title", "合同制职工人数");
				hd.put("value", contract.getWorkerTotalContractedNum());
				dList.add(hd);
			}
		}		
		rd.put("data", dList);
		request.getSession().setAttribute("data", rd);
		return mapping.findForward("pic");
	}
	
	public ActionForward piePic(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) {
		ViewContractDAO dao = new ViewContractDAO(request, response);
		String areaCode = request.getParameter("areaCode");
		List list = dao.findFromAreaCode(areaCode);
		Hashtable rd = new Hashtable();
		rd.put("pieTitle", "各类型企业合同制职工比例图");
		List dList = new Vector();
		if(list != null && list.size() > 0){
			for(int i = 0; i < list.size(); i ++){
				ViewContract vc = (ViewContract)list.get(i);
				ViewContractId contract = vc.getId();
				Hashtable hd = new Hashtable();
				hd.put("name", contract.getTypeName());
				hd.put("value", contract.getWorkerTotalContractedNum());
				dList.add(hd);
			}
		}		
		rd.put("data", dList);
		request.getSession().setAttribute("data", rd);
		return mapping.findForward("piePic");
	}
	
}